package com.example.xultimatex.myapplication;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import  android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

public class MyFirstApp extends AppCompatActivity
{
    protected static final String TAG = "MainActivity";
    private static  int red = 255,green = 255,blue = 255;

    private Button btn;
    private TextView tv;

    private SeekBar sb_R;
    private SeekBar sb_G;
    private SeekBar sb_B;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_first_app);

        btn = (Button)super.findViewById(R.id.button2);
        tv = (TextView)super.findViewById(R.id.textView);

        sb_R = super.findViewById(R.id.seekBar2_R);
        sb_G = super.findViewById(R.id.seekBar3_G);
        sb_B = super.findViewById(R.id.seekBar4_B);

        btn.setOnClickListener(new click1());

        sb_R.setOnSeekBarChangeListener(new changer());
        sb_G.setOnSeekBarChangeListener(new changer());
        sb_B.setOnSeekBarChangeListener(new changer());
    }
    private  class  click1 implements OnClickListener
    {
        public void onClick(View v)
        {
            Toast.makeText(getApplicationContext(),"随便写的",Toast.LENGTH_SHORT).show();
            tv.setTextColor(Color.BLUE);
        }

    }

    private class  changer implements SeekBar.OnSeekBarChangeListener
    {



        @Override
         public void onStopTrackingTouch(SeekBar seekBar)
        {
            Log.i(TAG,"onStopTrackingTouch");
        }

        @Override
         public void onStartTrackingTouch(SeekBar seekBar)
        {
            Log.i(TAG,"onStartTrackingTouch");
        }

        @Override
         public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser)
        {
            Log.i(TAG,"onProgressChanged");
            //tv.setText(seekBar.getId() + " "+ sb_R.getId());

            if(seekBar.getId() == sb_R.getId())
            {
                red = 255 - progress;

            }
            if(seekBar.getId() == sb_G.getId())
            {
                green = 255 - progress;

            }
            if(seekBar.getId() == sb_B.getId())
            {

                blue = 255 - progress;
            }

            //tv.setTextColor(Color.rgb(red,green,blue));
            tv.setBackgroundColor(Color.rgb(red,green,blue));
        }

    }

}
